home *** CD-ROM | disk | FTP | other *** search
- /* Bob Demo
- ** --------
- ** Blits a Worm to screen using a bob structure. This version does not
- ** include the sound from the assembler version.
- **
- ** To compile with SAS/C:
- **
- ** 1> sc BlitWorm.c link startup=LIB:gms.o data=far
- **
- */
-
- #include <proto/games.h>
-
- extern struct GMSBase *GMSBase;
- ULONG _XCEXIT = NULL;
- ULONG PREFSNAME = DEFAULT;
-
- struct GameScreen *GameScreen;
- struct Restorelist *Restorelist;
- struct Bob *BOB_Worm;
-
- #define TRUE 1
- #define FALSE 0
-
- void Demo(void);
-
- void main(void) {
- struct Picture *PIC_Bobs;
- struct Picture *PIC_Background;
-
- WORD WormFrames[] = {
- 0,0,0,0, 32,0,0,0, 64,0,0,0, 96,0,0,0,
- 128,0,0,0, 160,0,0,0, 192,0,0,0, 224,0,0,0,
- 256,0,0,0, 288,0,0,0, 0,48,0,0, 32,48,0,0,
- 64,48,0,0,
- -1
- };
-
- if (AllocBlitter() == ERR_OK) {
- if (AllocAudio() == ERR_OK) {
- if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
- GSA_Planes,5,
- GSA_ScrWidth,320,
- GSA_ScrHeight,256,
- GSA_Attrib,DBLBUFFER,
- TAGEND)) {
-
- if (PIC_Background = LoadPicTags(TAGS_PICTURE,NULL,
- PCA_Data,GameScreen->MemPtr2,
- PCA_Width,GameScreen->PicWidth,
- PCA_Height,GameScreen->PicHeight,
- PCA_Planes,GameScreen->Planes,
- PCA_ScrMode,GameScreen->ScrMode,
- PCA_ScrType,GameScreen->ScrType,
- PCA_Options,GETPALETTE,
- PCA_File,"GMS:demos/data/PIC.Green",
- TAGEND)) {
-
- GameScreen->Palette = PIC_Background->Palette;
- UpdatePalette(GameScreen);
- SwapBuffers(GameScreen);
- CopyBuffer(GameScreen,BUFFER1,BUFFER2);
-
- if (Restorelist = InitRestore(2,1)) {
-
- if (PIC_Bobs = LoadPicTags(TAGS_PICTURE,NULL,
- PCA_Planes,GameScreen->Planes,
- PCA_ScrType,GameScreen->ScrType,
- PCA_Options,VIDEOMEM,
- PCA_File,"GMS:demos/data/PIC.Rambo",
- TAGEND)) {
-
- if (BOB_Worm = InitBobTags(GameScreen,TAGS_BOB,NULL,
- BBA_Framelist,WormFrames,
- BBA_Width,32,
- BBA_Height,24,
- BBA_XCoord,150,
- BBA_YCoord,150,
- BBA_Attrib,RESTORE|GENMASKS|CLIP,
- BBA_PictureTags,PIC_Bobs,
- TAGEND)) {
-
- ShowScreen(GameScreen);
- Demo();
-
- FreeBob(BOB_Worm);
- }
- FreePic(PIC_Bobs);
- }
- FreeRestore(Restorelist);
- }
- FreePic(PIC_Background);
- }
- DeleteScreen(GameScreen);
- }
- FreeAudio();
- }
- FreeBlitter();
- }
- }
-
- /*=========================================================================*/
-
- void Demo(void)
- {
- ULONG mouse=0;
- UWORD anim=0,fire=FALSE;
-
- InitJoyPorts();
-
- do
- {
- Restore(GameScreen,Restorelist);
- DrawBob(GameScreen,BOB_Worm,BUFFER2,Restorelist);
- WaitVBL();
- SwapBuffers(GameScreen);
-
- /* Animate the Worm's movements */
-
- anim++;
-
- if (fire == FALSE) {
- if (anim > 5) {
- anim = 0;
- BOB_Worm->Frame++;
- if (BOB_Worm->Frame > 9)
- BOB_Worm->Frame = 0;
- }
- }
- else if (anim > 1) {
- anim = 0;
- if (BOB_Worm->Frame < 10)
- BOB_Worm->Frame = 9;
-
- BOB_Worm->Frame++;
-
- if (BOB_Worm->Frame > 12) {
- if (mouse & MB_LMB)
- BOB_Worm->Frame = 11;
- else {
- BOB_Worm->Frame = 0;
- fire = FALSE;
- }
- }
- }
-
- /* Get the user input */
-
- mouse = ReadJoyPort(JPORT1,JT_ZBXY);
- BOB_Worm->XCoord += GetX(mouse);
- BOB_Worm->YCoord += GetY(mouse);
- if (mouse & MB_LMB)
- fire = TRUE;
-
- } while (!(mouse & MB_RMB));
- }
-
-